﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using RotovapPlatform.Domain.Equipment.Device.IO;
using RotovapPlatform.Domain.Equipment.Interfaces.Base;

namespace RotovapPlatform.Domain.Equipment.Interfaces.Services
{
	/// <summary>
	/// IO信号应用服务接口
	/// 提供统一的IO信号访问入口，封装底层信号操作细节
	/// </summary>
	public interface IIOSignalAppService
	{
		/// <summary>
		/// 启动服务
		/// </summary>
		Task StartAsync();

		/// <summary>
		/// 停止服务
		/// </summary>
		Task StopAsync();

		/// <summary>
		/// 信号状态变化事件
		/// </summary>
		event EventHandler<IOSignalStateChangedEventArgs> SignalStateChanged;

		/// <summary>
		/// 获取所有DI信号
		/// </summary>
		IReadOnlyDictionary<string, IDISignal> GetAllDISignals();

		/// <summary>
		/// 获取所有DO信号
		/// </summary>
		IReadOnlyDictionary<string, IDOSignal> GetAllDOSignals();

		/// <summary>
		/// 获取所有AI信号
		/// </summary>
		IReadOnlyDictionary<string, IAISignal> GetAllAISignals();

		/// <summary>
		/// 获取DI信号
		/// </summary>
		IDISignal GetDISignal(DISignalId id);

		/// <summary>
		/// 获取DO信号
		/// </summary>
		IDOSignal GetDOSignal(DOSignalId id);

		/// <summary>
		/// 获取AI信号
		/// </summary>
		IAISignal GetAISignal(AISignalId id);

		/// <summary>
		/// 获取DI信号状态
		/// </summary>
		bool GetDIState(DISignalId id);

		/// <summary>
		/// 获取DO信号状态
		/// </summary>
		bool GetDOState(DOSignalId id);

		/// <summary>
		/// 获取AI信号值
		/// </summary>
		double GetAIValue(AISignalId id);

		/// <summary>
		/// 设置DO信号状态
		/// </summary>
		Task<bool> SetDOStateAsync(DOSignalId id, bool state);

		/// <summary>
		/// 强制刷新所有IO信号状态
		/// </summary>
		Task RefreshAllSignalsAsync();

		/// <summary>
		/// 获取冷凝器压力值
		/// </summary>
		/// <returns>压力值，单位：mbar</returns>
		double GetCondenserPressure();

		/// <summary>
		/// 注册信号状态变化回调函数
		/// </summary>
		void RegisterStateChangeCallback(Func<string, object, Task> callback);
	}
}